'use strict'
// const payload = {
//   data: {
//     action: 'exchange', // 'deny' || 'exchange' || 'broadcast'
//     payload: {}
//   },
//   meta: {
//     timestamp: 1512116201597,
//     client: '/webrtc#nNx88r1c5WuHf9XuAAAB',
//     target: '/webrtc#nNx88r1c5WuHf9XuAAAB'
//   }
// }

/**
 * @description 自定义错误类型
 * @param {*} param0 
 * @param errMsg 错误提示
 * @param errCode 错误码
 */
 function MError({ errMsg, errCode }) {
  this.message = errMsg;
  this.errCode = errCode;
}

module.exports = {
  parseMsg(action, payload = {}, metaData = {}) {
    const meta = {
      timestamp: Date.now()
    }
    Object.assign(meta, metaData)
    return {
      data: {
        action,
        payload
      },
      meta
    }
  },
  success(data = {}) {
    return { retCode: '0', errCode: '0', errMsg: '', data }
  },

  error(errCode = "1", errMsg = "操作失败") {
    throw new MError({ errMsg, errCode, retCode: '1' })
  },
}
